#include <chrono>
#include <memory>
#include <iostream>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int32_multi_array.hpp"
#include "main_while.hpp"
using namespace std::chrono_literals;
using std::placeholders::_1;
/* This example creates a subclass of Node and uses std::bind() to register a
 * member function as a callback from the timer. */

class E_Wheel_Msg : public rclcpp::Node
{
public:
  E_Wheel_Msg()
  : Node("e_wheel"), count_(0)
  {
    publisher_ = this->create_publisher<std_msgs::msg::Int32MultiArray>("e_wheel", 10);
    timer_ = this->create_wall_timer(
      20ms, std::bind(&E_Wheel_Msg::timer_callback, this));
    subscription_ = this->create_subscription<std_msgs::msg::Int32MultiArray>(
      "yaokong", 10, std::bind(&E_Wheel_Msg::topic_callback, this, _1));
      wm = new Wheel_in_out_module();
  }

private:
  void timer_callback()
  {
    auto message = std_msgs::msg::Int32MultiArray();
    message.data.resize(30);
    wm->node_time_callback( message.data);
   
    
    
    // RCLCPP_INFO(this->get_logger(), "Publishing: '%d'", message.data[0]);
    publisher_->publish(message);
  }

   void topic_callback(const std_msgs::msg::Int32MultiArray::SharedPtr msg) const
    {
      wm->node_topic_callback(msg->data);
     // RCLCPP_INFO(this->get_logger(), "e_wheel heard: '%d'", msg->data[0]);
    }
   rclcpp::Subscription<std_msgs::msg::Int32MultiArray>::SharedPtr subscription_;
  rclcpp::TimerBase::SharedPtr timer_;
  rclcpp::Publisher<std_msgs::msg::Int32MultiArray>::SharedPtr publisher_;

  size_t count_;
  int32_t cctt=10;
  int32_t wheel_out_msg[50],wheel_in_msg[50];
  Wheel_in_out_module *wm;
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<E_Wheel_Msg>());
  rclcpp::shutdown();
  return 0;
}